import { ref } from 'vue'


export function useSubmit(fn: any) {
  const saving = ref(false)
  const formRef = ref()
  //@ts-ignore
  const onSave: any = async (...val) => {
    if (await formRef.value.validate()) {
      return false
    } else {
      try {
        saving.value = true
        return await fn(...val)
      } finally {
        saving.value = false
      }
    }
  }
  return [onSave, saving, formRef]
}
